<?php

class MusicEvent
{
	private $ID;
	private $Date;
	private $Time;
	private $DateTime;
	private $Title;
	private $Choir;
	private $Note;
	private $Service;
	private $Psalms;
	private $Hymns;
	private $Introit;
	private $Responses;
	private $Mass;
	private $Canticles;
	private $Anthem;
	
	public function __construct($MusicListID)
	{
		$database=$GLOBALS['DATABASE']->Recopy();
	//	$sql= "SELECT * FROM MusicAdmin_MusicList WHERE MusicListID='".$MusicListID."'";
		
		$sql = "SELECT ml.Date as mlDate,";
		$sql .= "ml.Time as mlTime, ";
		$sql .= "ml.Choir as mlChoir, ";
		$sql .= "ml.Note as mlNote, ";
		$sql .= "ml.Service as mlService, ";
		$sql .= "ml.Psalms as mlPsalms, ";
		$sql .= "ml.Hymns as mlHymns, ";
		$sql .= "ml.Introit as mlIntroit, ";
		$sql .= "ml.Responses as mlResponses, ";
		$sql .= "ml.Mass as mlMass, ";
		$sql .= "ml.Canticles as mlCanticles, ";
		$sql .= "ml.Anthem as mlAnthem, ";
		$sql .= "e.Start as eStart, ";
		$sql .= "e.Title as eTitle ";
		$sql .= "FROM MusicAdmin_MusicList as ml ";
		$sql .= "INNER JOIN Events as e ON e.EventID=ml.SNAPEventID ";
		$sql .= "WHERE MusicListID='".$MusicListID."' ";
		
//		echo $sql;


		$database->executeSQL($sql);
		while($row=$database->getRow())
		{
			$this->ID = $MusicListID;
			
//			if(isset($row['mlDate']))      $this->Date      = $row['mlDate'];
//			if(isset($row['mlTime']))      $this->Time      = $row['mlTime'];
			if(isset($row['eStart']))      $this->DateTime  = $row['eStart'];
			if(isset($row['eTitle']))      $this->Title     = $row['eTitle'];
			
			if(isset($row['mlChoir']))     $this->Choir     = $row['mlChoir'];
			if(isset($row['mlNote']))      $this->Note      = $row['mlNote'];
			if(isset($row['mlService']))   $this->Service   = $row['mlService'];
			if(isset($row['mlPsalms']))    $this->Psalms    = $row['mlPsalms'];
			if(isset($row['mlHymns']))     $this->Hymns     = $row['mlHymns'];
			if(isset($row['mlIntroit']))   $this->Introit   = $row['mlIntroit'];
			if(isset($row['mlResponses'])) $this->Responses = $row['mlResponses'];
			if(isset($row['mlMass']))      $this->Mass      = $row['mlMass'];
			if(isset($row['mlCanticles'])) $this->Canticles = $row['mlCanticles'];
			if(isset($row['mlAnthem']))    $this->Anthem    = $row['mlAnthem'];
		}
	}
	
	public function getID()        {return $this->ID;}
	public function getDate()      {return $this->getDateTime()->format('Y-m-d');}
	public function getTime()      {return $this->getDateTime()->format('H:i');}
/*	public function getDateTime()  {return new DateTime($this->Date." ".$this->Time);}*/
	public function getDateTime()  {return new DateTime($this->DateTime);}
	public function getTitle()     {return $this->Title;}
	public function getChoir()     {return $this->Choir;}
	public function getNote()      {return $this->Note;}
	public function getService()   {return $this->Service;}
	public function getPsalms()    {return $this->Psalms;}
	public function getHymns()     {return $this->Hymns;}
	public function getIntroit()   {return $this->Introit;}
	public function getResponses() {return $this->Responses;}
	public function getMass()      {return $this->Mass;}
	public function getCanticles() {return $this->Canticles;}
	public function getAnthem()    {return $this->Anthem;}
	
	public function setDate($date)           {$this->Date = $date;}
	public function setTime($time)           {$this->Time = $time;}
	public function setTitle($title)         {$this->Title = $title;}
	public function setChoir($choir)         {$this->Choir = $choir;}
	public function setNote($note)           {$this->Note = $note;}
	public function setService($service)     {$this->Service = $service;}
	public function setPsalms($psalms)       {$this->Psalms = $psalms;}
	public function setHymns($hymns)         {$this->Hymns = $hymns;}
	public function setIntroit($introit)     {$this->Introit = $introit;}
	public function setResponses($responses) {$this->Responses = $responses;}
	public function setMass($mass)           {$this->Mass = $mass;}
	public function setCanticles($canticles) {$this->Canticles = $canticles;}
	public function setAnthem($anthem)       {$this->Anthem = $anthem;}
	
	public function save()
	{
		$database=$GLOBALS['DATABASE']->Recopy();
		$sql =  "UPDATE MusicAdmin_MusicList ";
		$sql .= "SET ";
/*		$sql .= "Date='".$this->Date."', "; These are all in Events not MusicAdmin
		$sql .= "Time='".$this->Time."', ";
		$sql .= "Title='".addslashes($this->Title)."', ";*/
		$sql .= "Choir='".addslashes($this->Choir)."', ";
		$sql .= "Note='".addslashes($this->Note)."', ";
		$sql .= "Service='".addslashes($this->Service)."', ";
		$sql .= "Psalms='".addslashes($this->Psalms)."', ";
		$sql .= "Hymns='".addslashes($this->Hymns)."', ";
		$sql .= "Introit='".addslashes($this->Introit)."', ";
		$sql .= "Responses='".addslashes($this->Responses)."', ";
		$sql .= "Mass='".addslashes($this->Mass)."', ";
		$sql .= "Canticles='".addslashes($this->Canticles)."', ";
		$sql .= "Anthem='".addslashes($this->Anthem)."' ";
		$sql .= "WHERE MusicListID='".$this->ID."'";
		echo $sql;
		$database->executeSQL($sql);
		echo "insert id ".mysql_insert_id();
	}
	
}
